window.onload=function(){
    axios.defaults.withCredentials = true;
    //获取用户登录
    axios.get('https://elm.cangdu.org/v1/user').then(res => {
        console.log(res);
    })
    //获取url内容
    let url = window.location.href;
    let paramStr = url.split('?')[1];
    let paramArr = paramStr.split('&');
    let paramObj = {};
    for (let i = 0; i < paramArr.length; i++) {
        let p_item = paramArr[i];
        paramObj[p_item.split('=')[0]] = p_item.split('=')[1]
    }
    console.log(paramObj);

    //获取订单详情
    $().ajax({
        url:`https://elm.cangdu.org/bos/v1/users/${paramObj.user_id}/orders/${paramObj.order_id}/snapshot`,
        method:'get',
        success:res=>{
            console.log(res);
            $('.kh_onemore').click(function(){
                window.location.href=`/pages/restaurant/restaurant.html?id=${res._doc.restaurant_id}`
            })
            $('.kh_sjname').click(function(){
                window.location.href=`/pages/restaurant/restaurant.html?id=${res._doc.restaurant_id}`
            })
            $('.kh_img').html(`<img src='//elm.cangdu.org/img/${res._doc.restaurant_image_url}'>`)
            $('.kh_name').html(`${res._doc.status_bar.title}`)
            $('.kh_sjname').html(`<div class='kh_img2'><img src='//elm.cangdu.org/img/${res._doc.restaurant_image_url}'></div>
            <div class='kh_name2'>${res._doc.restaurant_name}</div><div class='kh_to'>></div>
            `)
            for (let i = 0; i < res._doc.basket.group[0].length; i++) {
                $create('kh_goods','kh_goodsshow',`
                <div class='kh_1'>
                <div>
                ${res._doc.basket.group[0][i].name}
                </div>
                <div>
                X${res._doc.basket.group[0][i].quantity}
                </div>
                </div>
                <div>
                ￥${res._doc.basket.group[0][i].price}
                </div>
                `)
                
            }
            $('.kh_psf1').html( res._doc.basket.deliver_fee.price)
            $('.kh_realpay').html(`实付${res._doc.total_amount}.00`)
            $('.kh_sdtime').html(`送达时间： ${res.deliver_time}`)
            $('.kh_goodsaddress').html(`送货地址： ${res.addressDetail}`)
            $('.kh_ddh').html(`订单号： ${res._doc.id}`)
            $('.kh_payfs').html(`支付方式： ${res.pay_method}`)
            $('.kh_xdsj').html(`下单时间: ${res._doc.formatted_created_at} `)
        
        
        }
    })
}